home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5369 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  41 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!milyng
  3. From: mikael@pobox.com (Mikael Lyngvig)
  4. Subject: Re: Question : link c++ code into C code
  5. Message-ID: <milyngDM8Ixu.Kyp@netcom.com>
  6. Sender: milyng@netcom9.netcom.com
  7. Organization: Hacker's Paradise, Inc.
  8. X-Newsreader: WinVN 0.99.7
  9. References: <31110950.136D@genetique.uvsq.fr>
  10. Date: Sun, 4 Feb 1996 04:53:53 GMT
  11.  
  12. In article <31110950.136D@genetique.uvsq.fr>, forner@genetique.uvsq.fr says...
  13.  
  14. >I'd really like to know if it is possible to import C++ functions
  15. >or libs into a C program.
  16.  
  17. If you have the source code, you can do like this:
  18.  
  19. extern "C" int cppFunction(char *pString)
  20. {
  21. }
  22.  
  23.  
  24. If you don't have the source code (and therefore is using a C++ library), you 
  25. have to insert dispatcher functions:
  26.  
  27. extern "C" int cppFunction(char *pString)
  28. {
  29.    return libFunction(char *pString);
  30. }
  31.  
  32.  
  33. But it would probably be worth it to convert your C code to C++.  If your 
  34. program depends upon C++ libraries, it pretty much depends upon the 
  35. availability of a C++ compiler and thus might as well be C++ itself.
  36.  
  37.  
  38. Mikael
  39.  
  40.  
  41.